using ASP;
using HoWave.Common;
using HoWave.Data;
using HoWave.Data.Bll;
using HoWave.Data.Model;
using HoWave.Web.Admin;
using System;
using System.Web.Profile;
using System.Web.SessionState;
using System.Web.UI.WebControls;
public class Admin_MBF_UserGiftCardFaceValueEdit : Admin, IRequiresSessionState
{
	protected HiddenField h_id;
	protected DropDownList ddl_FestivalName;
	protected RequiredFieldValidator rfv1;
	protected TextBox txtFaceValue;
	protected RequiredFieldValidator rfv2;
	protected TextBox txtDiscountRate;
	protected RequiredFieldValidator rfv3;
	protected Button Add;
	protected Button ButtonReturn;
	protected DefaultProfile Profile
	{
		get
		{
			return (DefaultProfile)this.Context.Profile;
		}
	}
	protected global_asax ApplicationInstance
	{
		get
		{
			return (global_asax)this.Context.ApplicationInstance;
		}
	}
	protected void Page_Load(object sender, EventArgs e)
	{
		if (!this.Page.IsPostBack)
		{
			if (!base.admin.CheckAdminPower(39))
			{
				base.WriteLog("Modidy", Language.GetAdminMsg("Log/Access", "0"), "MBF_UserGiftCardFaceValueEdit");
				base.WriteRightErrMsg();
			}
			this.ddl_FestivalName.bindTableToDropDownList(Blls.bllFestival.GetDropDownListData(""), true, false);
			long num = (long)Fetch.GetID("id");
			if (num > 0L)
			{
				this.ShowInfo(num);
			}
		}
	}
	private void ShowInfo(long id)
	{
		UserGiftCardFaceValueModel model = Blls.bllGiftFaceValue.GetModel(id);
		if (model != null)
		{
			this.h_id.Value = model.id.ToString();
			this.txtDiscountRate.Text = model.DiscountRate.ToString();
			this.txtFaceValue.Text = model.FaceValue.ToString2();
			this.ddl_FestivalName.ddlSelect(model.FestivalName);
		}
	}
	protected void ButtonReturn_Click(object sender, EventArgs e)
	{
		base.Response.Redirect("MBF_UserGiftCardFaceValueSet.aspx?MenuID=5&MenuName=网站&FileName=礼品卡面值管理#pos_" + this.h_id.Value);
	}
	protected void Add_Click(object sender, EventArgs e)
	{
		string text = "";
		if (this.ddl_FestivalName.GetSelectValue(new string[0]) == "")
		{
			text += "请选择节日！\\n";
		}
		if (this.txtFaceValue.Text.Trim() == "")
		{
			text += "请填写面值！\\n";
		}
		if (this.txtDiscountRate.Text.Trim() == "")
		{
			text += "请填写奖励比率！\\n";
		}
		else
		{
			if (this.txtDiscountRate.Text.ToInt32(new int[0]) < 0 || this.txtDiscountRate.Text.ToInt32(new int[0]) > 100)
			{
				text += "请填写正确的奖励比率,0-100之间！\\n";
			}
		}
		if (text != "")
		{
			MessageBox.Show(this, text);
		}
		else
		{
			UserGiftCardFaceValueModel userGiftCardFaceValueModel = new UserGiftCardFaceValueModel();
			userGiftCardFaceValueModel.DiscountRate = new int?(this.txtDiscountRate.Text.Trim().ToInt32(new int[0]));
			userGiftCardFaceValueModel.FaceValue = new decimal?(this.txtFaceValue.Text.Trim().ToDecimal2());
			userGiftCardFaceValueModel.FestivalName = this.ddl_FestivalName.GetSelectValue(new string[0]);
			if (this.h_id.Value == "")
			{
				Blls.bllGiftFaceValue.Add(userGiftCardFaceValueModel);
			}
			else
			{
				userGiftCardFaceValueModel.id = new long?(long.Parse(this.h_id.Value));
				Blls.bllGiftFaceValue.Update(userGiftCardFaceValueModel);
			}
			MessageBox.ShowAndRedirect(this, "保存成功！", "MBF_UserGiftCardFaceValueSet.aspx?MenuID=5&MenuName=网站&FileName=礼品卡面值管理#pos_" + userGiftCardFaceValueModel.id);
		}
	}
}
